package cn.itcast.item.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MyConfig {

    //交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("item.topic",true,false);
    }

    //上架队列
    @Bean
    public Queue upShelf(){
        return new Queue("item_up_queue",true);
    }

    //下架队列
    @Bean
    public Queue downShelf(){
        return new Queue("item_down_queue",true);
    }

    //绑定交换机与队列
    @Bean
    public Binding insertQueueBinding(){
        return BindingBuilder.bind(upShelf()).to(topicExchange()).with("item.up");
    }

    @Bean
    public Binding deleteQueueBinding(){
        return BindingBuilder.bind(downShelf()).to(topicExchange()).with("item.down");
    }

}
